package com.zyw.customcalendar.common.dialog;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.PopupWindow;

public class CommonDialog {

	@SuppressLint("InflateParams")
	@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
	public static AlertDialog DropDown_Dialog(Context context, View view, WindowManager.LayoutParams lp){
		AlertDialog localAlertDialog = new AlertDialog.Builder(context, AlertDialog.THEME_DEVICE_DEFAULT_DARK).create();
		
		
		localAlertDialog.setView(view);
		
		Window win = localAlertDialog.getWindow();
		win.setGravity(Gravity.START | Gravity.TOP);
		
		localAlertDialog.setCanceledOnTouchOutside(true);
		localAlertDialog.show();
		
		win.setAttributes(lp);

		return localAlertDialog;
	}
	
	
	public static PopupWindow popUw;
	public static PopupWindow PopUpWindow(View view, View v, 
			Drawable drawable, int width, int height, int tx, int ty){
		popUw = new PopupWindow(view, width, height, true);
		popUw.setFocusable(true);
		popUw.setTouchable(true);
		popUw.setOutsideTouchable(true);
		popUw.showAsDropDown(v, tx, ty);
		popUw.setBackgroundDrawable(drawable);
		view.setOnTouchListener(new OnTouchListener() {  
			@SuppressLint("ClickableViewAccessibility")
			@Override
			public boolean onTouch(View arg0, MotionEvent arg1) {
				// TODO Auto-generated method stub
				if (popUw != null && popUw.isShowing()) {  
					popUw.dismiss();  
					popUw = null;  
                }  
                return false;  
			}  
        });  
		return popUw;
	}
	
	
	
	public static AlertDialog Date_AlterDialog(){
		return null;
	}
}
